import { Injectable } from '@nestjs/common';
import { GoodCategoryEntity } from '../entities';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { CreateGoodCategoryDto } from '../dto/create_category.dto';

@Injectable()
export class CategoryService {
  constructor(
    @InjectRepository(GoodCategoryEntity)
    private readonly goodCategoryRepository: Repository<GoodCategoryEntity>,
  ) {}
  async list() {
    return await this.goodCategoryRepository.find();
  }

  async create(body: CreateGoodCategoryDto) {
    return await this.goodCategoryRepository.save(body);
  }

  async update(id, body: CreateGoodCategoryDto) {
    return await this.goodCategoryRepository.update(id, body);
  }

  async delete(id: string) {
    try {
      await this.goodCategoryRepository.delete(id);
      return true;
    } catch (error) {
      return false;
    }
  }
}
